import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[][] matrix = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    matrix[i][j] = in.nextInt();
                }
                in.nextLine();
            }
            int q = in.nextInt();
            in.nextLine();
            int oneCount = 0;
            int twoCount = 0;
            for (int i = 0; i < q; i++) {
                int tmp = in.nextInt();
                in.nextLine();
                if (tmp == 1) {
                    oneCount++;
                } else {
                    twoCount++;
                }
            }
            oneCount %= 2;
            twoCount %= 2;
            if (oneCount != 0) {
                for (int i = 0; i <= (n-1)/2; i++) {
                    for (int j = 0; j < n-i; j++) {
                        int tmp = matrix[i][j];
                        matrix[i][j] = matrix[n-1-i][n-1-j];
                        matrix[n-1-i][n-1-j] = tmp;
                    }
                }
            }
            if (twoCount != 0) {
                for (int i = 0; i < n/2; i++) {
                    int[] tmp = matrix[i];
                    matrix[i] = matrix[n-1-i];
                    matrix[n-1-i] = tmp;
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print(matrix[i][j]);
                    if (j != n-1) {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
    }
}
